package com.stars.empoly.update.util

import android.Manifest
import android.annotation.SuppressLint
import androidx.fragment.app.FragmentActivity
import com.yanzhenjie.permission.AndPermission

@SuppressLint("CheckResult")
inline fun FragmentActivity.requestEachCombinedPermission(vararg permissions:String,
                                                          crossinline onGranted:() -> Unit,
                                                          crossinline onDefined:() -> Unit,
                                                          crossinline onSettingOrDefined:() -> Unit){




    AndPermission.with(this)
        .runtime()
        .permission(
            permissions
        )
        .onGranted { data ->
          //所有权限都同意了
            onGranted()
        }
        .onDenied {//拒绝了
            onDefined()
        }
        .start()


//    //TODO 这个rxpermissions的库我引入无效，大致就是获取权限的功能
//    val rxPermissions = RxPermissions(this)
//    rxPermissions.requestEachCombined(*permissions)
//            .subscribe {
//                if(it.granted){
//                    // All permissions are granted !
//                    onGranted()
//                }else if (it.shouldShowRequestPermissionRationale){
//                    //第一次请求权限被禁止，但未选择【不再提醒】
//                    //拒绝了
//                    onDefined()
//                }else{
//                    onSettingOrDefined()
//                }
//            }
}



